<template>
  <div class="app-container">
    <div class="custom_card">
      <Tabs
        :list="tabs_list"
        :column="6"
        :active="activeIndex"
        :minWidth="150"
        @tabs_click="secondedTypeChange"
        calss="menuTabs"
      ></Tabs>
    </div>
    <div class="custom_card_0" v-show="showSearch">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="同行名称" prop="sameJobName">
          <el-input
            v-model="queryParams.sameJobName"
            placeholder="请输入同行名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="车牌号" prop="carNo">
          <el-input
            v-model="queryParams.carNo"
            placeholder="请输入车牌号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input
            v-model="queryParams.orderNo"
            placeholder="请输入订单编号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="结算方式" prop="settlementWay">
          <el-select
            v-model="queryParams.settlementWay"
            placeholder="请选择结算方式"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in dict.type.settlement_way"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="借调状态" prop="secondedStatus">
          <el-select
            v-model="queryParams.secondedStatus"
            placeholder="请选择借调状态"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in dict.type.secondments_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索
          </el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
          </el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="custom_card">
      <el-row :gutter="10" class="mb10">
        <el-col :span="1.5">
          <el-button
            class="first-plain-btn" size="medium"
            icon="el-icon-plus"
            @click="handleAdd"
            v-hasPermi="['seconded:seconded:add']"
          >新增
          </el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            class="sec-plain-btn" size="medium"
            icon="el-icon-download"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['seconded:seconded:export']"
          >导出
          </el-button
          >
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
      <el-table
        v-loading="loading"
        :data="secondedList"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="操作"
          align="center"
          fixed
          class-name="small-padding fixed-width"
          width="180"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleEndSeconded(scope.row, 2)"
            >查看
            </el-button
            >
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.secondedStatus == 1 && scope.row.settlementStatus == 1"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['seconded:seconded:edit']"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.secondedStatus == 1 && scope.row.settlementStatus == 1"
              @click="handleDelete(scope.row)"
              v-hasPermi="['seconded:seconded:edit']"
            >删除
            </el-button>
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.secondedStatus == 1"
              @click="handleEndSeconded(scope.row, 1)"
              v-hasPermi="['seconded:seconded:edit']"
            >结束借调
            </el-button
            >
          </template>
        </el-table-column>
        <el-table-column
          label="同行名称"
          align="center"
          prop="sameJobName"
          min-width="150"
          show-overflow-tooltip
        />
        <el-table-column
          label="借调状态"
          align="center"
          prop="secondedStatus"
          min-width="130"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.secondments_state"
              :value="scope.row.secondedStatus"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="借调车辆"
          align="center"
          prop="carNo"
          min-width="130"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.carNo || '--' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单信息"
          align="center"
          prop="orderNo"
          min-width="280"
          show-overflow-tooltip
          v-if="queryParams.secondedType == 1"
          key="11"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.secondedType == 1">
              {{ scope.row.orderNo }} {{ scope.row.modelName }}
            </span>
            <span v-if="scope.row.secondedType == 2">--</span>
          </template>
        </el-table-column>
        <el-table-column
          label="借调时间"
          align="center"
          min-width="240"
          show-overflow-tooltip
          key="12"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.startTime || '--' }}</span>
            <span>至</span>
            <span v-if="scope.row.secondedStatus == 1">{{
                scope.row.estimateEndTime || '--'
              }}</span>
            <span v-if="scope.row.secondedStatus == 2">{{
                scope.row.actualEndTime || '--'
              }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="借调天数"
          align="center"
          min-width="130px"
          show-overflow-tooltip
          key="13"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.secondedStatus == 1"
            >{{ scope.row.dayCount || '--' }}天</span
            >
            <span v-if="scope.row.secondedStatus == 2"
            >{{ scope.row.actualDay || '--' }}天</span
            >
          </template>
        </el-table-column>

        <el-table-column
          v-if="activeIndex == 1"
          label="借调单价"
          align="center"
          prop="secondedUnitPrice"
          min-width="130px"
          show-overflow-tooltip
          key="14"
        >
          <template v-slot="{row}">
            <span v-if="row.secondedUnitPrice">{{ row.secondedUnitPrice }}元/天</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单费用"
          align="center"
          prop="rentTotal"
          min-width="130px"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.rentTotal || "--" }}元</span>
          </template>
        </el-table-column>
        <el-table-column
          label="借调费用"
          align="center"
          prop="totalRent"
          min-width="130px"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.amount || "--" }}元</span>
          </template>
        </el-table-column>
        <el-table-column
          label="结算方式"
          align="center"
          prop="settlementWay"
          show-overflow-tooltip
          min-width="130px"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.settlement_way"
              :value="scope.row.settlementWay"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="应付时间"
          align="center"
          prop="payableTime"
          min-width="160px"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="财务收款时间"
          align="center"
          prop="receiptTime"
          min-width="160px"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="经办人"
          align="center"
          prop="sysUserName"
          min-width="130px"
          show-overflow-tooltip
        />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <el-dialog
      title="新增借调"
      :visible.sync="dialogVisible"
      width="500px"
      :before-close="cancelDialogVisible"
    >
      <el-form ref="form1" :model="form1" :rules="rules" label-width="80px">
        <el-form-item label="借调类型" prop="secondedType">
          <el-radio-group v-model="form1.secondedType" size="medium">
            <el-radio
              v-for="dict in dict.type.seconded_type"
              :label="parseInt(dict.value)"
              :value="parseInt(dict.value)"
              :key="parseInt(dict.value)"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialogVisible">取 消</el-button>
        <el-button type="primary" @click="addCouponManage">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 添加或修改同行借调对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="借调类型" prop="secondedType">
              <el-select
                v-model="form.secondedType"
                style="width: 100%"
                placeholder="请选择借调类型"
                clearable
                disabled
                size="small"
              >
                <el-option
                  v-for="dict in dict.type.seconded_type"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24"></el-col>
          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="订单号" prop="orderNo">
              <el-input
                v-model="form.orderNo"
                readonly
                placeholder="请选择订单号"
              >
                <el-button
                  slot="append"
                  v-if="form.id == null"
                  @click="selectOrder"
                >选择
                </el-button
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="品牌/车系/车型" prop="modelName">
              <el-input
                v-model="form.modelName"
                readonly
                placeholder="选择订单自动带出"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="租赁时间" prop="time">
              <el-input
                v-model="form.time"
                readonly
                placeholder="选择订单自动带出"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="借调同行"
              prop="sameJobName"
              style="width: 100%"
            >
              <el-input
                v-model="form.sameJobName"
                readonly
                placeholder="请选择借调同行"
              >
                <el-button
                  slot="append"
                  v-if="form.id == null"
                  @click="selectSame"
                >选择
                </el-button
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="车牌号" prop="carNo">
              <el-input v-model="form.carNo" placeholder="请输入车牌号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="车架号" prop="vinNo">
              <el-input v-model="form.vinNo" placeholder="请输入车架号"/>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="form.secondedType == 2">
            <el-form-item label="车牌号" prop="carNo" style="width: 50%">
              <el-input
                v-model="form.carNo"
                readonly
                placeholder="请选择车牌号"
              >
                <el-button
                  slot="append"
                  v-if="form.id == null"
                  @click="selectCar"
                >选择
                </el-button
                >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借调开始日期" prop="startTime">
              <el-date-picker
                v-model="form.startTime"
                type="datetime"
                style="width: 100%"
                placeholder="开始日期"
                @change="changeStartTime"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <template v-if="form.secondedType == 2">

            <el-col :span="12">
              <el-form-item label="借调结束日期" prop="estimateEndTime">
                <el-date-picker
                  v-model="form.estimateEndTime"
                  type="datetime"
                  style="width: 100%"
                  placeholder="结束日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  @change="changeEndTime"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="借调天数" prop="estimateDay">
                <el-input
                  v-model="form.estimateDay"
                  readonly
                  placeholder="选择借调时间自动带出"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="借调费用" prop="totalRent">
                <el-input v-model="form.totalRent" placeholder="请输入借调费用" @keyup.native="form.totalRent = oninput(form.totalRent,2)"/>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.carSource == 6">
              <el-form-item label="托管费用" prop="hostingFees">
                <el-input v-model="form.hostingFees" placeholder="请输入托管费用" @keyup.native="form.hostingFees = oninput(form.hostingFees,2)"/>
              </el-form-item>
            </el-col>
          </template>

          <el-col :span="12" v-if="form.secondedType == 1">
            <el-form-item label="借调单价" prop="secondedUnitPrice">
              <div style="display: flex;">
                <el-input style="width: 80%" v-model="form.secondedUnitPrice" placeholder="请输入借调单价"
                          @keyup.native="form.secondedUnitPrice = oninput(form.secondedUnitPrice,2)"/>
                <span>元/天</span>
              </div>

            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="结算方式" prop="settlementWay">
              <el-radio-group v-model="form.settlementWay" size="medium">
                <el-radio
                  v-for="dict in dict.type.settlement_way"
                  :label="parseInt(dict.value)"
                  :value="parseInt(dict.value)"
                  :key="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="车辆初始图片" prop="initialPicture">
              <ImageUpload isArray v-model="form.initialPicture" :limit="20" :zoom="0.6" :fileSize="20"></ImageUpload>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark" style="width: 50%">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer
      title="借调同行"
      :visible.sync="drawerFlag"
      :direction="direction"
      size="50%"
      :before-close="handleSameClose"
      :modal="false"
    >
      <div class="table-padding">
        <el-form
          :model="queryParamsSame"
          ref="querySameForm"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="名称" prop="name">
            <el-input
              v-model="queryParamsSame.name"
              placeholder="请输入名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuerySame"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuerySame"
            >搜索
            </el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuerySame"
            >重置
            </el-button
            >
          </el-form-item>
        </el-form>
        <el-table v-loading="loadingDrawer" :data="sameDrawerList" border>
          <el-table-column
            label="同行名称"
            align="center"
            min-width="120"
            show-overflow-tooltip
            prop="name"
          />
          <el-table-column
            label="联系人"
            align="center"
            min-width="120"
            show-overflow-tooltip
            prop="contact"
          />
          <el-table-column
            label="联系电话"
            align="center"
            min-width="120"
            show-overflow-tooltip
            prop="phone"
          />
          <el-table-column
            label="公司地址"
            align="center"
            min-width="120"
            show-overflow-tooltip
            prop="companyAddress"
          />
          <el-table-column
            label="公司电话"
            align="center"
            min-width="120"
            show-overflow-tooltip
            prop="companyPhone"
          />
          <el-table-column
            label="操作"
            align="center"
            fixed="left"
            class-name="small-padding fixed-width"
            width="100px"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleSameUpdate(scope.row)"
              >选择
              </el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="totalSame > 0"
          :total="totalSame"
          :page.sync="queryParamsSame.pageNum"
          :limit.sync="queryParamsSame.pageSize"
          @pagination="getSameList"
        />
      </div>
    </el-drawer>
    <el-drawer
      title="借调车辆"
      :visible.sync="drawerFlagCar"
      :direction="directionCar"
      size="50%"
      :before-close="handleCarClose"
      :modal="false"
    >
      <el-form
        :model="queryParamsCar"
        ref="queryCarForm"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="车牌号" prop="carNo">
          <el-input
            v-model="queryParamsCar.carNo"
            placeholder="请输入车牌号"
            clearable
            size="small"
            @keyup.enter.native="handleQueryCar"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQueryCar"
          >搜索
          </el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryCar"
          >重置
          </el-button
          >
        </el-form-item>
      </el-form>
      <el-table v-loading="loadingCarDrawer" :data="CarDrawerList">
        <el-table-column label="品牌/车系/车型" align="center">
          <template slot-scope="scope">
            {{
              scope.row.carBrandName +
              '/' +
              scope.row.carSeriesName +
              '/' +
              scope.row.carModelName
            }}
          </template>
        </el-table-column>
        <el-table-column label="车牌号" align="center" prop="carNo"/>
        <el-table-column label="车辆状态" align="center" prop="carStatus">
          <template slot-scope="scope">
            <div>
              <dict-tag
                :options="dict.type.car_status"
                :value="scope.row.carStatus"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          class-name="small-padding fixed-width"
          width="150px"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleCarUpdate(scope.row)"
            >选择
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalCar > 0"
        :total="totalCar"
        :page.sync="queryParamsCar.pageNum"
        :limit.sync="queryParamsCar.pageSize"
        @pagination="getCarList"
      />
    </el-drawer>
    <el-drawer
      title="订单列表"
      :visible.sync="drawerFlagOrder"
      :direction="directionOrder"
      size="50%"
      :before-close="handleOrderClose"
      :modal="false"
    >
      <div class="table-padding">
        <el-form
          :model="queryParamsOrder"
          ref="queryOrderForm"
          :inline="true"
          class="search"
          label-width="80px"
        >
          <el-form-item label="订单编号" prop="orderNo">
            <el-input
              v-model="queryParamsOrder.orderNo"
              clearable
              @1clear="handleQuery"
              style="width: 220px"
              placeholder="请输入订单编号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQueryOrder"
            >搜索
            </el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="resetQueryOrder"
            >重置
            </el-button
            >
          </el-form-item>
        </el-form>
        <el-table v-loading="loadingOrderDrawer" :data="OrderDrawerList" border>
          <el-table-column
            label="订单号"
            min-width="200"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              {{ row.orderNo }}
            </template>
          </el-table-column>
          <el-table-column
            label="承租人"
            min-width="130"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              <span>{{ row.memberName }}</span
              >、
              <span>{{ row.memberPhone }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="预计取还时间"
            min-width="180"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              <span style="color: #d9001b">取：{{ row.rentalStartTime }}</span
              >&nbsp;&nbsp;&nbsp;
              <span style="color: #dd5d1b">还：{{ row.rentalEndTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="租期"
            min-width="130"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              <div>{{ row.leaseDays }}天</div>
            </template>
          </el-table-column>
          <el-table-column
            label="预定车型"
            min-width="150"
            align="center"
            show-overflow-tooltip
          >
            <template slot-scope="{ row }">
              <span>{{ row.modelName }}</span>
            </template>
          </el-table-column>

          <el-table-column
            label="操作"
            align="center"
            fixed="left"
            class-name="small-padding fixed-width"
            width="100px"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleOrderUpdate(scope.row)"
              >选择
              </el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="totalOrder > 0"
          :total="totalOrder"
          :page.sync="queryParamsOrder.pageNum"
          :limit.sync="queryParamsOrder.pageSize"
          @pagination="getOrderList"
        />
      </div>
    </el-drawer>
    <el-drawer
      title="借调列表"
      :visible.sync="drawerFlagMonth"
      :direction="directionMonth"
      size="50%"
      :before-close="handleMonthClose"
      :modal="false"
    >
      <el-table v-loading="loadingMonthDrawer" :data="MonthDrawerList">
        <el-table-column label="同行名称" align="center" prop="sameJobName"/>
        <el-table-column
          label="借调车辆"
          align="center"
          prop="carNo"
          width="120"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.carNo }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="订单信息"
          align="center"
          prop="orderNo"
          width="200"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.secondedType == 1">{{
                scope.row.orderNo
              }}</span>
            <span v-if="scope.row.secondedType != 1">--</span>
          </template>
        </el-table-column>
        <el-table-column
          label="借调时间"
          align="center"
          prop="startTime"
          width="180"
        >
          <template slot-scope="scope">
            <div>
              <span>{{ scope.row.startTime }}</span> <br/>
              <span>至</span> <br/>
              <span>{{ scope.row.estimateEndTime }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="借调天数" align="center" prop="estimateDay">
          <template slot-scope="scope">
            <span>{{ scope.row.dayCount }}天</span>
          </template>
        </el-table-column>
        <el-table-column label="借调费用" align="center" prop="totalRent">
          <template slot-scope="scope">
            <span>{{ scope.row.amount || "--" }}元</span>
          </template>
        </el-table-column>
        <el-table-column label="经办人" align="center" prop="sysUserName"/>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['seconded:seconded:edit']"
            >修改
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalMonth > 0"
        :total="totalMonth"
        :page.sync="queryParamsMonth.pageNum"
        :limit.sync="queryParamsMonth.pageSize"
        @pagination="getMonthList"
      />
    </el-drawer>

    <!-- 详情 -->
    <el-dialog
      :title="titleShow"
      :visible.sync="openShow"
      append-to-body
      width="900px"
    >
      <el-form
        ref="formShow"
        :model="formShow"
        :rules="finishRules"
        label-width="110px"
      >
        <el-row>
          <MmvTitle title="借调信息" v-if="detailFlag"></MmvTitle>
          <el-col :span="24" class="table-padding">
            <el-descriptions
              :column="2"
              border
              :labelStyle="{ width: '140px' }"
            >
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">订单号</template>
                {{ formShow.orderNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">车牌号</template>
                {{ formShow.carNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">车架号</template>
                {{ formShow.vinNo }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调类型</template>
                <dict-tag
                  :options="dict.type.seconded_type"
                  :value="formShow.secondedType"
                />
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">品牌/车系/车型</template>
                {{ formShow.modelName }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">租赁时间</template>
                {{ formShow.time }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调同行</template>
                {{ formShow.sameJobName }}
              </el-descriptions-item>
              <!--              <el-descriptions-item label-class-name="my-descriptions-label"  v-if="form.secondedType == 1">-->
              <!--                <template-->
              <!--                  slot="label"-->
              <!--                  v-if="form.secondedType == 1 || form.secondedType == 2"-->
              <!--                  >车牌号</template-->
              <!--                >-->
              <!--                {{ formShow.time }}-->
              <!--              </el-descriptions-item>-->
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调开始日期</template>
                {{ formShow.startTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">预约借调结束日期</template>
                {{ formShow.estimateEndTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">预约借调天数</template>
                {{ formShow.estimateDay }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">实际结束日期</template>
                {{ formShow.actualEndTime }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">实际借调天数</template>
                {{ formShow.actualDay }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedType == 1">
                <template slot="label">借调单价</template>
                {{ formShow.secondedUnitPrice }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">借调费用</template>
                {{ formShow.totalRent }}
              </el-descriptions-item>
              <el-descriptions-item v-if="formShow.secondedType==2&&formShow.carSource==6&&formShow.secondedStatus == 2" label-class-name="my-descriptions-label">
                <template slot="label">托管费用</template>
                {{ formShow.hostingFees }}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">结算方式</template>
                <el-radio-group v-model="formShow.settlementWay" size="medium">
                  <el-radio
                    v-for="dict in dict.type.settlement_way"
                    :label="parseInt(dict.value)"
                    disabled="disabled"
                    :value="parseInt(dict.value)"
                    :key="parseInt(dict.value)"
                    v-if="dict.value == formShow.settlementWay"
                  >{{ dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label" span="2">
                <template slot="label">车辆初始图片</template>
                <template v-for="item in formShow.initialPicture">
                  <el-image :key="item" :src="item|mmvImageUrl" :preview-src-list="[$mmvImageUrl(item)]" class="mmv-image" fit="contain"></el-image>
                </template>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="my-descriptions-label">
                <template slot="label">借调备注</template>
                {{ formShow.remark }}
              </el-descriptions-item>

              <el-descriptions-item label-class-name="my-descriptions-label" span="2" v-if="formShow.secondedStatus == 2">
                <template slot="label">借调结束图片</template>
                <template v-for="item in formShow.endPicture">
                  <el-image :key="item" :src="item|mmvImageUrl" :preview-src-list="[$mmvImageUrl(item)]" class="mmv-image" fit="contain"></el-image>
                </template>
              </el-descriptions-item>

              <el-descriptions-item label-class-name="my-descriptions-label" v-if="formShow.secondedStatus == 2">
                <template slot="label">结束借调备注</template>
                {{ formShow.endRemark }}
              </el-descriptions-item>
            </el-descriptions>
          </el-col>
        </el-row>
        <MmvTitle
          title="结束借调"
          v-if="formShow.secondedStatus == 1 && detailFlag"
        ></MmvTitle>
        <el-row
          v-if="formShow.secondedStatus == 1 && detailFlag"
          class="table-padding"
        >
          <el-col :span="12" v-if="formShow.secondedType==1">
            <el-form-item label="实际结束日期" prop="actualEndTime">
              <el-date-picker
                v-model="formShow.actualEndTime"
                style="width: 100%"
                type="datetime"
                placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="changeEndSecondmentTime"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="借调天数" prop="actualDay">
              <el-input
                v-model="formShow.actualDay"
                placeholder="请输入借调天数"
                @keyup.native="formShow.actualDay = oninput(formShow.actualDay,2)"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="formShow.secondedType == 1">
            <el-form-item label="借调单价" prop="secondedUnitPrice">
              <el-input disabled v-model="formShow.secondedUnitPrice" placeholder="请输入借调单价"
                        @keyup.native="formShow.secondedUnitPrice = oninput(formShow.secondedUnitPrice,2)"/>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="formShow.secondedType==2">
            <el-form-item label="实际结束日期" prop="actualEndTime">
              <el-date-picker
                v-model="formShow.actualEndTime"
                style="width: 100%"
                type="datetime"
                placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="changeEndSecondmentTime"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="借调费用" prop="totalRent">
              <el-input
                v-if="amountFlag"
                v-model="formShow.totalRent"
                placeholder="请输入借调费用"
              />
              <el-input
                v-else
                disabled
                v-model="formShow.totalRent"
                placeholder="请输入借调费用"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="formShow.secondedType == 2 && formShow.carSource==6">
            <el-form-item label="托管费用" prop="hostingFees">
              <el-input v-model="formShow.hostingFees" placeholder="请输入托管费用" @keyup.native="formShow.hostingFees = oninput(formShow.hostingFees,2)"/>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="借调结束图片" prop="endPicture">
              <ImageUpload isArray v-model="formShow.endPicture" :limit="20" :zoom="0.6"></ImageUpload>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark" style="width: 80%">
              <el-input
                v-model="formShow.endRemark"
                type="textarea"
                placeholder="请输入内容"
                maxlength="200"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEndForm" v-if="detailFlag"
        >确 定
        </el-button
        >
        <el-button @click="cancelShow" v-if="detailFlag">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import MmvTitle from '@/components/MmvUI/MmvTitle.vue'
import Tabs from '@/components/custom/tabs.vue'
import {
  listSeconded,
  monthListSeconded,
  listCount,
  endEdit,
  getSeconded,
  delSeconded,
  addSeconded,
  updateSeconded,
  exportSeconded,
} from '@/api/seconded/seconded'
import {listBasic} from '@/api/car/car_basic'
import {listJob} from '@/api/seconded/job'
import {index} from '@/api/order/index'

export default {
  name: 'Seconded',
  components: {
    MmvTitle,
    Tabs,
  },
  dicts: [
    'settlement_way',
    'settlement_status',
    'secondments_state',
    'seconded_type',
    'car_status',
    'memberType',
  ],
  data() {
    return {
      activeIndex: 1,
      rowCenter: {
        'text-align': 'center',
      },
      // 遮罩层
      loading: true,
      detailFlag: false,
      drawerFlag: false,
      loadingDrawer: false,
      direction: 'rtl',
      sameDrawerList: [],
      totalSame: 0,
      drawerFlagCar: false,
      loadingCarDrawer: false,
      directionCar: 'rtl',
      CarDrawerList: [],
      drawerFlagOrder: false,
      loadingOrderDrawer: false,
      directionOrder: 'rtl',
      OrderDrawerList: [],
      totalOrder: 0,
      totalCar: 0,
      drawerFlagMonth: false,
      loadingMonthDrawer: false,
      directionMonth: 'rtl',
      MonthDrawerList: [],
      totalMonth: 0,

      queryParamsMonth: {
        pageNum: 1,
        pageSize: 10,
        id: null,
      },

      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 同行借调表格数据
      secondedList: [],
      form1: {secondedType: 1},
      dialogVisible: false,
      // 弹出层标题
      title: '',
      titleShow: '',
      // 是否显示弹出层
      open: false,
      tabs_list: [
        {
          key: '1',
          name: '借入车辆',
          count: 0,
        },
        {
          key: '2',
          name: '借出车辆',
          count: 0,
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sameJobId: null,
        sameJobName: null,
        sysUserId: null,
        sysUserName: null,
        carId: null,
        carNo: null,
        orderNo: null,
        startTime: null,
        estimateEndTime: null,
        actualEndTime: null,
        estimateDay: null,
        actualDay: null,
        dailyRent: null,
        totalRent: null,
        otherFee: null,
        settlementWay: null,
        secondedStatus: null,
        settlementStatus: null,
        receiptTime: null,
        deptId: null,
        tenantId: null,
        secondedType: 1,
      },
      formShow: {
        settlementWay: null,
      },
      amountFlag: false,
      openShow: false,
      queryParamsSame: {
        pageNum: 1,
        pageSize: 10,
        name: null,
      },
      queryParamsOrder: {
        pageNum: 1,
        pageSize: 10,
        /*orderStatus:2,*/
        clickOrder: 1,
      },
      queryParamsCar: {
        pageNum: 1,
        pageSize: 10,
        carNo: null,
        carStatus: -1,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sameJobName: [
          {required: true, message: '同行名称不能为空', trigger: 'change'},
        ],
        orderNo: [
          {required: true, message: '订单不能为空', trigger: 'change'},
        ],
        startTime: [
          {required: true, message: '借调开始时间不能为空', trigger: 'blur'},
        ],
        // estimateEndTime: [
        //   { required: true, message: '借调结束时间不能为空', trigger: 'blur' },
        // ],
        settlementWay: [
          {required: true, message: '结算方式不能为空', trigger: 'blur'},
        ],
        carNo: [
          {required: true, message: '车牌号不能为空', trigger: 'change'},
        ],
        // vinNo: [
        //   { required: true, message: '车架号不能为空', trigger: 'change' },
        // ],
        secondedUnitPrice: [
          {required: true, message: '借调单价不能为空', trigger: 'change'},
        ],
      },
      finishRules: {
        actualDay: [
          {required: true, message: '借调天数不能为空', trigger: 'change'},
        ],
        totalRent: [
          {required: true, message: '借调费用不能为空', trigger: 'change'},
        ],
        hostingFees: [
          {required: true, message: '托管费用不能为空', trigger: 'change'},
        ],
        actualEndTime: [
          {required: true, message: '借调结束时间不能为空', trigger: 'blur'},
        ],
      }
    }
  },
  watch: {
    'formShow.actualDay': {
      handler(value) {
        if (this.formShow.actualDay && this.formShow.secondedUnitPrice && this.formShow.secondedType == 1) {
          const secondedUnitPrice = Number(this.formShow.secondedUnitPrice)
          const actualDay = Number(this.formShow.actualDay)
          console.log('22222', secondedUnitPrice, actualDay)
          this.formShow.totalRent = secondedUnitPrice * actualDay
        }
      },
      // immediate:true,
      deep: true
    },
  },
  created() {
    this.getList()
  },
  methods: {
    changeStartTime(val) {
      let date = new Date(val).getTime()
      this.startTime = date
      if (this.form.estimateEndTime) {
        if (this.startTime > new Date(this.form.estimateEndTime).getTime()) {
          this.$message.error('结束时间不能小于开始时间')
          this.form.startTime = ''
          this.startTime = null
        } else {
          let iDays = parseInt(
            Math.abs(
              new Date(this.form.estimateEndTime).getTime() - this.startTime
            ) /
            1000 /
            60 /
            60 /
            24
          )
          let y =
            (new Date(this.form.estimateEndTime).getTime() - this.startTime) %
            (1000 * 60 * 60 * 24)
          if (y > 0) {
            iDays = iDays + 1
          }
          this.form.estimateDay = iDays
        }
      }
    },
    handleEndSeconded(row, type) {
      this.detailFlag = false
      this.formShow.amount = this.formShow.totalRent
      if (type == 1) {
        this.detailFlag = true
      }
      //未收款可以进行编辑金额
      if (row.settlementStatus == 1) {
        this.amountFlag = true
      }
      const id = row.id || this.ids
      getSeconded(id).then((response) => {
        this.formShow = response.data
        console.log(this.formShow)
        if (type == 1) {
          if (this.formShow.actualEndTime == null) {
            this.formShow.actualEndTime = this.formShow.rentalEndTime
          }
          if (this.formShow.actualDay == null) {
            this.formShow.actualDay = this.formShow.estimateDay
          }

        }
        this.formShow.time =
          response.data.rentalStartTime + ' 至 ' + response.data.rentalEndTime
        this.openShow = true
        this.titleShow = type == 1 ? '结束借调' : '借调详情'
      })
    },
    /** 结束提交按钮 */
    submitEndForm() {
      this.$refs['formShow'].validate((valid) => {
        if (valid) {
          console.log(this.formShow)
          endEdit(this.formShow).then((response) => {
            this.$modal.msgSuccess('结束借调成功')
            this.openShow = false
            this.getList()
          })
        }
      })
    },
    handleMonthClose(done) {
      done()
    },
    selectMonth() {
      this.resetQueryMonth()
      this.drawerFlagMonth = true
      this.getMonthList()
    },
    handleQueryMonth() {
      this.queryParamsMonth.pageNum = 1
      this.getMonthList()
    },
    /** 查询借调同行列表 */
    getMonthList() {
      this.loadingDrawer = true
      monthListSeconded(this.queryParamsMonth).then((response) => {
        this.MonthDrawerList = response.rows
        this.totalMonth = response.total
        this.loadingDrawer = false
      })
    },
    /** 重置按钮操作 */
    resetQueryMonth() {
      this.resetForm('queryMonthForm')
      this.handleQueryMonth()
    },
    secondedClick(row) {
      this.queryParamsMonth.id = row
      this.selectMonth()
    },
    handleOrderClose(done) {
      done()
    },
    selectOrder() {
      this.resetQueryOrder()
      this.drawerFlagOrder = true
      this.getOrderList()
    },
    handleQueryOrder() {
      this.queryParamsOrder.pageNum = 1
      this.getOrderList()
    },
    /** 查询借调同行列表 */
    getOrderList() {
      this.loadingDrawer = true
      index(this.queryParamsOrder).then((response) => {
        this.OrderDrawerList = response.rows
        this.totalOrder = response.total
        this.loadingDrawer = false
      })
    },
    /** 重置按钮操作 */
    resetQueryOrder() {
      this.resetForm('queryOrderForm')
      this.handleQueryOrder()
    },
    //选择订单
    handleOrderUpdate(row) {
      this.form.orderNo = row.orderNo
      this.form.modelName = row.modelName
      this.form.startTime = row.rentalStartTime + ':00'
      this.form.time = row.rentalStartTime + ' 至 ' + row.rentalEndTime
      // this.form.estimateEndTime = row.rentalEndTime + ':00'
      // this.form.estimateDay = row.leaseDays
      this.drawerFlagOrder = false
    },
    //选择日期后触发change方法，将开始和结束时间转为时间戳进行对比，不符合约束条件就清空该日期重新选择
    changeEndTime(val) {

      if (val) {
        let date = new Date(val).getTime()
        this.endTime = date
        if (this.form.startTime) {
          if (this.endTime < new Date(this.form.startTime).getTime()) {
            this.$message.error('结束时间不能小开始时间')
            this.form.estimateEndTime = ''
            this.endTime = null
          } else {
            let iDays = parseInt(
              Math.abs(this.endTime - new Date(this.form.startTime).getTime()) /
              1000 /
              60 /
              60 /
              24
            )
            let y =
              (this.endTime - new Date(this.form.startTime).getTime()) %
              (1000 * 60 * 60 * 24)
            if (y > 0) {
              iDays = iDays + 1
            }
            this.form.estimateDay = iDays
          }
        } else {
          this.$message.error('请选择开始时间')
          this.form.estimateEndTime = ''
          this.endTime = null
        }
      }else {
        console.log('-----', val)
          this.form.estimateDay = null
      }
    },
    changeEndSecondmentTime(val) {
      let date = new Date(val).getTime()
      this.endTime = date
      if (this.formShow.startTime) {
        if (this.endTime < new Date(this.formShow.startTime).getTime()) {
          this.$message.error('结束时间不能小开始时间')
          this.formShow.actualEndTime = ''
          this.endTime = null
        } else {
          let iDays = parseInt(
            Math.abs(
              this.endTime - new Date(this.formShow.startTime).getTime()
            ) /
            1000 /
            60 /
            60 /
            24
          )
          let y =
            (this.endTime - new Date(this.formShow.startTime).getTime()) %
            (1000 * 60 * 60 * 24)
          if (y > 0) {
            iDays = iDays + 1
          }
          this.formShow.actualDay = iDays
        }
      } else {
        this.$message.error('请选择开始时间')
        this.formShow.actualEndTime = ''
        this.endTime = null
      }
    },
    handleSameClose(done) {
      done()
    },
    selectSame() {
      this.resetQuerySame()
      this.drawerFlag = true
      this.getSameList()
    },
    handleQuerySame() {
      this.queryParamsSame.pageNum = 1
      this.getSameList()
    },
    /** 查询借调同行列表 */
    getSameList() {
      this.loadingDrawer = true
      listJob(this.queryParamsSame).then((response) => {
        this.sameDrawerList = response.rows
        this.totalSame = response.total
        this.loadingDrawer = false
      })
    },
    /** 重置按钮操作 */
    resetQuerySame() {
      this.resetForm('querySameForm')
      this.handleQuerySame()
    },
    //选择同行
    handleSameUpdate(row) {
      this.form.sameJobId = row.id
      this.form.sameJobName = row.name
      this.drawerFlag = false
    },
    handleCarClose(done) {
      done()
    },
    selectCar() {
      this.resetQueryCar()
      this.drawerFlagCar = true
      this.getCarList()
    },
    handleQueryCar() {
      this.queryParamsCar.pageNum = 1
      this.queryParamsCar.carStatus = -1
      this.getCarList()
    },
    /** 查询借调同行列表 */
    getCarList() {
      this.loadingDrawer = true
      listBasic(this.queryParamsCar).then((response) => {
        this.CarDrawerList = response.rows
        this.totalCar = response.total
        this.loadingDrawer = false
      })
    },
    /** 重置按钮操作 */
    resetQueryCar() {
      this.resetForm('queryCarForm')
      this.handleQueryCar()
    },
    //选择车辆
    handleCarUpdate(row) {
      this.form.carId = row.id
      this.form.carNo = row.carNo
      this.form.carSource = row.carSource
      this.drawerFlagCar = false
    },
    addCouponManage() {
      this.$refs['form1'].validate((valid) => {
        if (valid) {
          let secondedType = this.form1.secondedType
          this.dialogVisible = false
          this.reset()
          this.form.secondedType = secondedType
          this.form.settlementWay = 1
          this.open = true
          this.title = this.form.secondedType == 1 ? '借入车辆' : '借出车辆'
        }
      })
    },
    cancelDialogVisible() {
      this.dialogVisible = false
      this.resetform1()
    },
    // 表单重置
    resetform1() {
      this.form1 = {
        secondedType: 1,
      }
      this.resetForm('form1')
    },
    secondedTypeChange(val) {
      this.activeIndex = val
      this.queryParams.secondedType = val
      this.getList()
    },
    /** 查询同行借调列表 */
    getList() {
      this.getListCount()
      this.loading = true
      listSeconded(this.queryParams).then((response) => {
        this.secondedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 查询同行借调列表 */
    getListCount() {
      listCount({}).then((response) => {
        this.tabs_list[0].count = response.data.count
        this.tabs_list[1].count = response.data.count1
      })
    },
    // 取消按钮
    cancelShow() {
      this.openShow = false
      this.reset()
    },
    cancel() {
      this.open = false
      this.resetShow()
    },
    resetShow() {
      this.formShow = {}
      this.resetForm('formShow')
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sameJobId: null,
        sameJobName: null,
        sysUserId: null,
        sysUserName: null,
        carId: null,
        carNo: null,
        vinNo: null,
        orderNo: null,
        startTime: null,
        estimateEndTime: null,
        actualEndTime: null,
        estimateDay: null,
        actualDay: null,
        dailyRent: null,
        totalRent: null,
        otherFee: null,
        settlementWay: null,
        secondedStatus: 0,
        settlementStatus: 0,
        receiptTime: null,
        deptId: null,
        tenantId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        secondedUnitPrice: null,
        hostingFees: null,
        carSource: null,
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.resetForm('form1')
      this.dialogVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getSeconded(id).then((response) => {
        this.form = response.data
        this.form.time =
          response.data.rentalStartTime + ' 至 ' + response.data.rentalEndTime
        this.open = true
        this.title = '修改同行借调'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (!this.form.initialPicture) {
            this.form.initialPicture = null
          }
          if (this.form.id != null) {
            updateSeconded(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功')
              this.open = false

              this.getList()
            })
          } else {
            addSeconded(this.form).then((response) => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal
        .confirm('是否确认删除吗？')
        .then(function () {
          return delSeconded(ids)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal
        .confirm('是否确认导出所有同行借调数据项？')
        .then(() => {
          this.exportLoading = true
          return exportSeconded(queryParams)
        })
        .then((response) => {
          this.$download.name(response.msg)
          this.exportLoading = false
        })
        .catch(() => {
        })
    },
  },
}
</script>

